package com.zht.user_manger.objectmodel.enums;

import org.apache.commons.lang3.ObjectUtils;

public enum UserRole {

    USER("普通用户","normal"),
    ENJOIN("封禁","enjoin"),
    ADMIN("管理者","admin");

    private final String authority;

    private final String value;

    UserRole(String authority, String value) {
        this.authority = authority;
        this.value = value;
    }

    public String getAuthority() {
        return authority;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static UserRole getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (UserRole anEnum : UserRole.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

}
